package logic

import (
	"context"
	"jd_mall_users/user_srv/model/mysql"

	"jd_mall_users/user_srv/internal/svc"
	"jd_mall_users/user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateAvatarLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateAvatarLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAvatarLogic {
	return &UpdateAvatarLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateAvatarLogic) UpdateAvatar(in *user.UpdateAvatarRequest) (*user.UpdateAvatarResponse, error) {
	u := mysql.User{}
	err := u.UpdateAvatar(in.AvatarUrl)
	if err != nil {
		logx.Error("修改头像失败:", err)
		return nil, err
	}

	return &user.UpdateAvatarResponse{}, nil
}
